//
//  SidebarViewController.m
//  news
//
//  Created by lanou on 15/12/22.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "SidebarViewController.h"
#import "BaseTabBarController.h"

@interface SidebarViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) BaseTabBarController *baseTBC;

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, retain) NSArray *sidebarArray;

@end

@implementation SidebarViewController

- (NSArray *)sidebarArray
{
    if (!_sidebarArray) {
        _sidebarArray = @[@"收藏", @"字体设置", @"推送设置", @"清除缓存", @"夜间模式", @"关于", @"意见反馈"];
    }
    return _sidebarArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(-100, 150, 200, 350) style:(UITableViewStylePlain)];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cebianlan"];
    
    [self.view addSubview:self.tableView];
    
    self.baseTBC = [[BaseTabBarController alloc] init];
    [self.view addSubview:self.baseTBC.view];
    
    [self addChildViewController:self.baseTBC];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sidebar) name:@"isSidebar" object:nil];
    
    // Do any additional setup after loading the view.
}

static bool isSidebar = NO;

- (void)sidebar
{
    if (isSidebar) {
        [UIView animateWithDuration:0.5 animations:^{
            self.tableView.frame = CGRectMake(-100, 150, 200, 300);
            self.baseTBC.view.frame = CGRectMake(0, 0, kWidth, kHeight);
        } completion:^(BOOL finished) {
            isSidebar = NO;
        }];
    } else {
        [UIView animateWithDuration:0.5 animations:^{
            self.tableView.frame = CGRectMake(10, 150, 200, 300);
            self.baseTBC.view.frame = CGRectMake(200, 60, kWidth * 0.8, kHeight * 0.8);
        } completion:^(BOOL finished) {
            isSidebar = YES;
        }];
    }
}

#pragma mark -
#pragma mark ---加载侧边栏---

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cebianlan" forIndexPath:indexPath];
    cell.textLabel.text = self.sidebarArray[indexPath.row];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
